Skip to content

Fix GRANDPA set ID handling - #2971

Draft
UnArbosFive wants to merge 1 commit into
fix/testnet-grandpa-warp-sync-v2from
fix/grandpa-setid
Draft

Fix GRANDPA set ID handling#2971
UnArbosFive wants to merge 1 commit into
fix/testnet-grandpa-warp-sync-v2from
fix/grandpa-setid

Conversation

@UnArbosFive

Copy link
Copy Markdown
Contributor

Summary

  • advance Grandpa::CurrentSetId after a successful admin-scheduled authority change
  • apply Finney's historical initial set-ID correction once at warp-sync start instead of once per proof fragment
  • preserve the testnet checkpoint behavior introduced by Fix testnet GRANDPA warp sync checkpoints #2959
  • update runtime versioning, weight accounting, and regression coverage

Root cause

The admin scheduling path called Grandpa::schedule_change directly and therefore bypassed the set-ID bookkeeping normally performed by pallet-grandpa's session integration. This runtime does not use pallet-session, so the successful scheduling path must perform that bookkeeping explicitly.

Separately, the pinned SDK's legacy initial-set-ID mechanism adds its offset inside the proof-fragment loop. Finney needs the historical offset only at the beginning of verification; applying it to every fragment over-counts later authority-set transitions.

Impact

Authority rotations scheduled through admin-utils now keep on-chain GRANDPA set-ID state aligned with the scheduled transition. Finney warp-sync verification also carries the corrected set ID forward normally across subsequent transitions.

Validation

  • CARGO_NET_OFFLINE=true cargo test -p pallet-admin-utils --locked
  • SKIP_WASM_BUILD=1 CARGO_NET_OFFLINE=true cargo test -p node-subtensor grandpa_warp_sync --locked -- --nocapture
  • SKIP_WASM_BUILD=1 CARGO_NET_OFFLINE=true cargo test -p node-subtensor-runtime --lib --locked
  • SKIP_WASM_BUILD=1 CARGO_NET_OFFLINE=true cargo clippy -p pallet-admin-utils -p node-subtensor-runtime -p node-subtensor --tests --no-deps --locked
  • cargo fmt --all -- --check
  • git diff --check

Dependency

This is intentionally stacked on #2959 while that PR remains open. Retarget this PR to main after #2959 merges.

@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
subtensor Ready Ready Preview, Comment Jul 23, 2026 5:11pm

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread runtime/src/lib.rs
Comment on lines +1001 to +1004
Grandpa::schedule_change(next_authorities, in_blocks, forced)?;
// This runtime does not use pallet-session, so mirror the bookkeeping performed by
// pallet-grandpa's session handler after it successfully schedules an authority change.
pallet_grandpa::CurrentSetId::<Runtime>::mutate(|set_id| *set_id += 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Delay set-ID advancement until the authority change takes effect

schedule_change accepts an arbitrary in_blocks, but this advances CurrentSetId immediately while Grandpa::grandpa_authorities() remains the old set until the scheduled block. During that window, a restarting node reads the new set ID through GrandpaApi::current_set_id() alongside the old authorities and can initialize GRANDPA with an invalid (set_id, authorities) pair, impairing finality. The session-handler pattern cited here is safe only when scheduling at the session transition; it cannot be copied unchanged to this delayed admin API. Advance the ID when the change is enacted, or constrain this path to an immediate change and reject nonzero delays. Add a restart/runtime-API regression test for the pending-change window.

@github-actions

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: VULNERABLE

BASELINE scrutiny: repository admin with matching author/committer and substantial merged history; no Gittensor association. Legitimate stacked branch targeting #2959.

The warp-sync wrapper is narrowly scoped to Finney and preserves the testnet checkpoint path. However, the runtime bookkeeping change exposes an incorrect GRANDPA set ID during delayed authority changes.

Findings

Sev File Finding
HIGH runtime/src/lib.rs:1004 Delay set-ID advancement until the authority change takes effect inline

Conclusion

The PR is legitimate-looking, but incrementing CurrentSetId before a delayed authority change takes effect can make restarted nodes initialize GRANDPA with mismatched authorities and threaten finality liveness.


# 🔍 AI Review — Auditor (domain review) has not yet run on this PR.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot mentioned this pull request Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant